package com.stt.base.controller;

import com.stt.base.model.Device;
import com.stt.base.model.TimerTask;
import com.stt.base.service.DeviceService;
import com.stt.base.service.TimerTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 智能家居控制器
 */
@RestController
@RequestMapping("/api/smart")
public class SmartHomeController {
    
    @Autowired
    private DeviceService deviceService;
    
    @Autowired
    private TimerTaskService timerTaskService;
    
    /**
     * 获取所有设备
     */
    @GetMapping("/devices")
    public List<Device> getAllDevices() {
        return deviceService.getAllDevices();
    }
    
    /**
     * 控制设备开关
     */
    @PostMapping("/devices/{id}/status")
    public void controlDeviceStatus(@PathVariable Long id, @RequestParam boolean status) {
        deviceService.controlDeviceStatus(id, status);
    }
    
    /**
     * 控制设备参数
     */
    @PostMapping("/devices/{id}/parameter")
    public void controlDeviceParameter(@PathVariable Long id, @RequestParam Integer parameter) {
        deviceService.controlDeviceParameter(id, parameter);
    }
    
    /**
     * 创建定时任务
     */
    @PostMapping("/tasks")
    public TimerTask createTask(@RequestBody TimerTask task) {
        return timerTaskService.createTask(task);
    }
    
    /**
     * 获取所有定时任务
     */
    @GetMapping("/tasks")
    public List<TimerTask> getAllTasks() {
        return timerTaskService.getAllTasks();
    }
    
    /**
     * 删除定时任务
     */
    @DeleteMapping("/tasks/{id}")
    public void deleteTask(@PathVariable Long id) {
        timerTaskService.deleteTask(id);
    }
} 